1196C - Robot Breakout - CodeForces Solution


implementation *1500

Please click on ads to support us..

Python Code:



import sys
from sys import stdin

tt = int(stdin.readline())

ANS = []

for loop in range(tt):

    n = int(stdin.readline())

    L = U = -10**5
    R = D = 10**5

    for i in range(n):

        x,y,f1,f2,f3,f4 = map(int,stdin.readline().split())

        if f1 == 0:
            L = max(L,x)
        if f3 == 0:
            R = min(R,x)

        if f4 == 0:
            U = max(U,y)
        if f2 == 0:
            D = min(D,y)

    if L > R or U > D:
        ANS.append("0")
    else:
        ANS.append("1 " + str(L) + " " + str(U) )

print ("\n".join(ANS))

C++ Code:

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
struct DSU {
	int size;
	int componentCount;
	int* parent;
	int* height;

	DSU(int _size) {
		size = _size;
		componentCount = size;
		parent = new int[size];
		height = new int[size];

		for (int i = 0; i < size; i++) {
			parent[i] = i;
			height[i] = 1;
		}
	}

	int getRep(int a) {
		int tmp = a;
		while (parent[tmp] != tmp) {
			tmp = parent[tmp];
		}
		parent[a] = tmp;
		return tmp;
	}

	void connect(int a, int b) {
		a = getRep(a), b = getRep(b);
		if (a == b) return;
		if (height[a] < height[b]) {
			parent[a] = b;
		}
		else if (height[b] < height[a]) {
			parent[b] = a;
		}
		else {
			height[a]++;
			parent[b] = a;
		}
		componentCount--;
	}
};
long long binPow(long long x, long long y, long long mod) {
	if (y == 0ll) return 1ll;

	long long tmp = binPow(x, y / 2ll, mod);
	if (y % 2ll == 0ll) return (tmp * tmp) % mod;
	else return (((x * tmp) %mod) * tmp) % mod;
}

void solve() {
	int n;
	cin >> n;

	//x y left up right down

	vector<vector<int>> robots(n, vector<int>(6));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			cin >> robots[i][j];
		}
	}

	int l = -100000, u = 100000, d = -100000, r = 100000;
	for (int i = 0; i < n; i++) {
		int _l = (robots[i][2] ? -100000 : robots[i][0]);
		int _u = (robots[i][3] ? 100000 : robots[i][1]);
		int _r = (robots[i][4] ? 100000 : robots[i][0]);
		int _d = (robots[i][5] ? -100000 : robots[i][1]);

		l = max(l, _l);
		u = min(u, _u);
		r = min(r, _r);
		d = max(d, _d);
	}

	//cout << "*** ";

	if (l > r || d > u) {
		cout << "0\n";
		return;
	}

	cout << "1 " << l << " " << u << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	bool unlimited = true;

	if (unlimited) {
		int t;
		cin >> t;
		while (t--) solve();
	}
	else {
		solve();
	}

	return 0;
}


Comments

Submit
0 Comments
More Questions

1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC
466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume